define(function(){
	//创建cookie
	function createCookie(key,value,expires,path){
		var cookieText = encodeURIComponent(key) + "=" + encodeURIComponent(value);
		if(typeof expires === "number"){
			var date = new Date();
			date.setDate(date.getDate() + expires);
			cookieText += ";expires=" + date; 
		}
		if(path){
			cookieText += ";path=" + path;
		}
		document.cookie = cookieText;
	}
	//获取cookie
	function getCookie(key){
		var arr = document.cookie.split("; ");
		for(var i = 0;i < arr.length;i ++){
			var list = arr[i].split("=");
			if(list[0] == encodeURIComponent(key)){
				return decodeURIComponent(list[1]);
			}
		}
	}
	//删除cookie
	function removeCookie(key,path){
		if(path){
			document.cookie = encodeURIComponent(key) + "=;expires=" + new Date(0) + ";path=" + path;
		}else{
			document.cookie = encodeURIComponent(key) + "=;expires=" + new Date(0);
		}
	}
	//获取单个个数
	function getNum(key,type){
		var arr = document.cookie.split("; ");
		for(var i = 0;i < arr.length;i ++){
			var list = arr[i].split("=");
			if(list[0] == encodeURIComponent(key)){
				var obj = eval("(" + decodeURIComponent(list[1]) + ")");
				return obj[type];
			}
		}
	}
	//获取总数
	function getTotal(){
		var arr = document.cookie.split("; ");
		var total = 0;
		for(var i = 0;i < arr.length;i ++){
			var list = arr[i].split("=");
			var obj = eval("(" + decodeURIComponent(list[1]) + ")");
			//console.log(obj);
			if(obj){
				if(obj.goodNum){
					total += parseInt(obj.goodNum);
				}
			}
			console.log(total)
		}
		return total;
	}
	//{"src":"../img/list/list_1_1.jpg","message":"53度 茅台","price":"354","num":"12","sale":"立减20"}
	return {
		createCookie:createCookie,
		getCookie:getCookie,
		removeCookie:removeCookie,
		getNum:getNum,
		getTotal:getTotal
	};
})
	